package com.dynamixsoftware.printershare.smb.ntlmssp;

import com.dynamixsoftware.printershare.smb.netbios.NbtAddress;
import com.dynamixsoftware.printershare.smb.util.Dumper;
import java.io.IOException;
import java.net.UnknownHostException;

public class Type2Message
  extends NtlmMessage
{
  private static final String DEFAULT_DOMAIN;
  private static final int DEFAULT_FLAGS = 513;
  private static final byte[] DEFAULT_TARGET_INFORMATION;
  private byte[] challenge;
  private byte[] context;
  private String target;
  private byte[] targetInformation;
  
  static
  {
    DEFAULT_DOMAIN = null;
    Object localObject1 = new byte[0];
    if (DEFAULT_DOMAIN != null) {}
    try
    {
      byte[] arrayOfByte3 = DEFAULT_DOMAIN.getBytes("UTF-16LE");
      localObject1 = arrayOfByte3;
    }
    catch (IOException localIOException2)
    {
      label33:
      int i;
      Object localObject2;
      break label33;
    }
    i = localObject1.length;
    localObject2 = new byte[0];
    try
    {
      str = NbtAddress.getLocalHost().getHostName();
      if (str == null) {}
    }
    catch (UnknownHostException localUnknownHostException)
    {
      String str;
      byte[] arrayOfByte2;
      label65:
      int j;
      int k;
      int m;
      label197:
      break label65;
    }
    try
    {
      arrayOfByte2 = str.getBytes("UTF-16LE");
      localObject2 = arrayOfByte2;
    }
    catch (IOException localIOException1)
    {
      break label65;
    }
    j = localObject2.length;
    if (i > 0)
    {
      k = i + 4;
      if (j <= 0) {
        break label197;
      }
    }
    for (m = j + 4;; m = 0)
    {
      byte[] arrayOfByte1 = new byte[4 + (m + k)];
      int n = 0;
      if (i > 0)
      {
        writeUShort(arrayOfByte1, 0, 2);
        int i2 = 0 + 2;
        writeUShort(arrayOfByte1, i2, i);
        System.arraycopy(localObject1, 0, arrayOfByte1, i2 + 2, i);
        n = i + 4;
      }
      if (j > 0)
      {
        writeUShort(arrayOfByte1, n, 1);
        int i1 = n + 2;
        writeUShort(arrayOfByte1, i1, j);
        System.arraycopy(localObject2, 0, arrayOfByte1, i1 + 2, j);
      }
      DEFAULT_TARGET_INFORMATION = arrayOfByte1;
      return;
      k = 0;
      break;
    }
  }
  
  public Type2Message()
  {
    this(getDefaultFlags(), null, null);
  }
  
  private Type2Message(int paramInt, byte[] paramArrayOfByte, String paramString)
  {
    setFlags(paramInt);
    setChallenge(paramArrayOfByte);
    setTarget(paramString);
    if (paramString != null) {
      setTargetInformation(getDefaultTargetInformation());
    }
  }
  
  public Type2Message(byte[] paramArrayOfByte)
    throws IOException
  {
    parse(paramArrayOfByte);
  }
  
  private static int getDefaultFlags()
  {
    return DEFAULT_FLAGS;
  }
  
  private static byte[] getDefaultTargetInformation()
  {
    return DEFAULT_TARGET_INFORMATION;
  }
  
  private void parse(byte[] paramArrayOfByte)
    throws IOException
  {
    for (int i = 0; i < 8; i++) {
      if (paramArrayOfByte[i] != NTLMSSP_SIGNATURE[i]) {
        throw new IOException("Not an NTLMSSP message.");
      }
    }
    if (readULong(paramArrayOfByte, 8) != 2) {
      throw new IOException("Not a Type 2 message.");
    }
    int j = readULong(paramArrayOfByte, 20);
    setFlags(j);
    byte[] arrayOfByte1 = readSecurityBuffer(paramArrayOfByte, 12);
    int k = arrayOfByte1.length;
    String str1 = null;
    String str2;
    if (k != 0)
    {
      if ((j & 0x1) != 0)
      {
        str2 = "UTF-16LE";
        str1 = new String(arrayOfByte1, str2);
      }
    }
    else {
      setTarget(str1);
    }
    int n;
    for (int m = 24;; m++) {
      if (m < 32)
      {
        if (paramArrayOfByte[m] != 0)
        {
          byte[] arrayOfByte4 = new byte[8];
          System.arraycopy(paramArrayOfByte, 24, arrayOfByte4, 0, 8);
          setChallenge(arrayOfByte4);
        }
      }
      else
      {
        n = readULong(paramArrayOfByte, 16);
        if ((n != 32) && (paramArrayOfByte.length != 32)) {
          break label195;
        }
        return;
        str2 = getOEMEncoding();
        break;
      }
    }
    label195:
    for (int i1 = 32;; i1++) {
      if (i1 < 40)
      {
        if (paramArrayOfByte[i1] != 0)
        {
          byte[] arrayOfByte3 = new byte[8];
          System.arraycopy(paramArrayOfByte, 32, arrayOfByte3, 0, 8);
          setContext(arrayOfByte3);
        }
      }
      else
      {
        if ((n == 40) || (paramArrayOfByte.length == 40)) {
          break;
        }
        byte[] arrayOfByte2 = readSecurityBuffer(paramArrayOfByte, 40);
        if (arrayOfByte2.length == 0) {
          break;
        }
        setTargetInformation(arrayOfByte2);
        return;
      }
    }
  }
  
  public byte[] getChallenge()
  {
    return this.challenge;
  }
  
  public byte[] getContext()
  {
    return this.context;
  }
  
  public String getTarget()
  {
    return this.target;
  }
  
  public byte[] getTargetInformation()
  {
    return this.targetInformation;
  }
  
  public void setChallenge(byte[] paramArrayOfByte)
  {
    this.challenge = paramArrayOfByte;
  }
  
  public void setContext(byte[] paramArrayOfByte)
  {
    this.context = paramArrayOfByte;
  }
  
  public void setTarget(String paramString)
  {
    this.target = paramString;
  }
  
  public void setTargetInformation(byte[] paramArrayOfByte)
  {
    this.targetInformation = paramArrayOfByte;
  }
  
  public byte[] toByteArray()
  {
    for (;;)
    {
      byte[] arrayOfByte2;
      byte[] arrayOfByte3;
      int i;
      int j;
      byte[] arrayOfByte5;
      try
      {
        String str = getTarget();
        byte[] arrayOfByte1 = getChallenge();
        arrayOfByte2 = getContext();
        arrayOfByte3 = getTargetInformation();
        i = getFlags();
        byte[] arrayOfByte4 = new byte[0];
        if ((i & 0x4) != 0)
        {
          if ((str == null) || (str.length() == 0)) {
            break label279;
          }
          if ((i & 0x1) != 0) {
            arrayOfByte4 = str.getBytes("UTF-16LE");
          }
        }
        else
        {
          if (arrayOfByte3 == null) {
            break label253;
          }
          i |= 0x800000;
          if (arrayOfByte2 != null) {
            break label253;
          }
          arrayOfByte2 = new byte[8];
          break label253;
          int k = j + arrayOfByte4.length;
          int m = 0;
          if (arrayOfByte3 != null) {
            m = arrayOfByte3.length;
          }
          arrayOfByte5 = new byte[m + k];
          System.arraycopy(NTLMSSP_SIGNATURE, 0, arrayOfByte5, 0, 8);
          writeULong(arrayOfByte5, 8, 2);
          writeSecurityBuffer(arrayOfByte5, 12, j, arrayOfByte4);
          writeULong(arrayOfByte5, 20, i);
          if (arrayOfByte1 == null) {
            continue;
          }
          System.arraycopy(arrayOfByte1, 0, arrayOfByte5, 24, 8);
          if (arrayOfByte2 != null) {
            System.arraycopy(arrayOfByte2, 0, arrayOfByte5, 32, 8);
          }
          if (arrayOfByte3 == null) {
            break label276;
          }
          writeSecurityBuffer(arrayOfByte5, 40, j + arrayOfByte4.length, arrayOfByte3);
          return arrayOfByte5;
        }
        arrayOfByte4 = str.toUpperCase().getBytes(getOEMEncoding());
        continue;
        arrayOfByte1 = new byte[8];
        continue;
        j = 32;
      }
      catch (IOException localIOException)
      {
        throw new IllegalStateException(localIOException.getMessage());
      }
      label253:
      if (arrayOfByte2 != null) {
        j += 8;
      }
      if (arrayOfByte3 != null)
      {
        j += 8;
        continue;
        label276:
        return arrayOfByte5;
        label279:
        i &= 0xFFFFFFFB;
      }
    }
  }
  
  public String toString()
  {
    String str1 = getTarget();
    byte[] arrayOfByte1 = getChallenge();
    byte[] arrayOfByte2 = getContext();
    byte[] arrayOfByte3 = getTargetInformation();
    StringBuilder localStringBuilder1 = new StringBuilder().append("Type2Message[target=").append(str1).append(",challenge=");
    String str2;
    String str3;
    label74:
    StringBuilder localStringBuilder3;
    if (arrayOfByte1 == null)
    {
      str2 = "null";
      StringBuilder localStringBuilder2 = localStringBuilder1.append(str2).append(",context=");
      if (arrayOfByte2 != null) {
        break label160;
      }
      str3 = "null";
      localStringBuilder3 = localStringBuilder2.append(str3).append(",targetInformation=");
      if (arrayOfByte3 != null) {
        break label190;
      }
    }
    label160:
    label190:
    for (String str4 = "null";; str4 = "<" + arrayOfByte3.length + " bytes>")
    {
      return str4 + ",flags=0x" + Dumper.toHexString(getFlags(), 8) + "]";
      str2 = "<" + arrayOfByte1.length + " bytes>";
      break;
      str3 = "<" + arrayOfByte2.length + " bytes>";
      break label74;
    }
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.smb.ntlmssp.Type2Message
 * JD-Core Version:    0.7.0.1
 */